package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;
import android.widget.TextView;

import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.CourseBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by ky on 2018/1/9.
 */

public class MoreRecycleradatper extends ListBaseAdapter<CourseBean.RowsBean> {

    protected Context context = null;
    public MoreRecycleradatper(Context context){
        super(context);
        this.context = context;
    }

    @Override
    public int getLayoutId() {
        return R.layout.more_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        CourseBean.RowsBean rowsBean = getDataList().get(position);

        ImageView img_more =  holder.getView(R.id.img_more);
        TextView tv_title = holder.getView(R.id.tv_more2);
        TextView tv_date = holder.getView(R.id.tv_more1);
        tv_title.setText(rowsBean.getNewsTitle());
        //tv_content.setText(rowsBean.getNewsBrief());
        long creationDate = rowsBean.getCreationDate();
        //mill为你龙类型的时间戳
        Date date=new Date(creationDate);
        String creation="";
        try {
            //yyyy表示年MM表示月dd表示日
            //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
            SimpleDateFormat sdf=new SimpleDateFormat("MM月dd日");
            //进行格式化
            creation=sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        tv_date.setText(creation);

        if(rowsBean.getTopPicUrl()!=null) {
            if (rowsBean.getTopPicUrl().contains("aliyuncs.com")) {
                Picasso.with(context).load(Uri.parse(rowsBean.getTopPicUrl())).placeholder(R.mipmap.no_data).into(img_more);//加载图片
            } else {
                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(rowsBean.getTopPicUrl()))).placeholder(R.mipmap.no_data).into(img_more);//加载图片
            }

        }else{
            img_more.setImageResource(R.mipmap.nodataphoto);
        }



    }




}